package com.shushan.pages;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.shushan.base.Constants;
import com.shushan.base.NavigationLoseActivity;
import com.shushan.exam.ExamActivity;
import com.shushan.exercise.SyncExerciseActivity;
import com.shushan.home.bean.RewardToyBean;
import com.shushan.shushanbao.R;
import com.shushan.util.ImageUtils;
import com.shushan.util.Session;

import java.util.List;

/**
 * @ClassName: ToyAwardDetailsActivity
 * @Desciption: //玩具奖励详情页
 * @author: zhangshihao
 * @date: 2018-04-10
 */
public class ToyAwardDetailsActivity extends NavigationLoseActivity implements View.OnClickListener{

    private static final String TAG = ToyAwardDetailsActivity.class.getSimpleName();

    private TextView tvName;
    private TextView tvTask;
    private TextView tvDescription;
    private ImageView ivPic;
    private Button btnGoComplete;

    private RewardToyBean rewardToyBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_toy_award_details);

        setTitle("我的奖品");

        rewardToyBean = (RewardToyBean) Session.getSession().get("rewardToyBean");

        initView();
    }

    private void initView(){
        btnGoComplete = findViewById(R.id.btn_details_go_complete);
        tvName = findViewById(R.id.tv_details_toy_name);
        tvTask = findViewById(R.id.tv_details_complete_condition);
        tvDescription = findViewById(R.id.tv_details_complete_condition_2);
        ivPic = findViewById(R.id.iv_details_toy_pic);

        btnGoComplete.setOnClickListener(this);

        if(rewardToyBean != null){
            tvName.setText("奖品名称：" + rewardToyBean.name);
            tvTask.setText("完成情况：" + rewardToyBean.task);
            List<String> desList = rewardToyBean.getDescription_list();
            tvDescription.setText(desList.get(0)+"，并且\n"+desList.get(1)+"\n"+desList.get(2)+"\n"+desList.get(3));
            ImageUtils.loadWXImageView(this,rewardToyBean.pic,ivPic);
        }

    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.btn_details_go_complete){
            int type = rewardToyBean.practice_type;
            switch (type){
                case Constants.TYPE_SYNC_EXERCISE:
                    Session.getSession().put("rewardToyBean",rewardToyBean);

                    Intent syncIntent = new Intent(this,SyncExerciseActivity.class);
                    syncIntent.putExtra("awardType",2);
                    startActivityAllow(syncIntent);
                    break;
                case Constants.TYPE_SMART_EXERCISE:
                    startSmartExam(rewardToyBean);
                    break;
                case Constants.TYPE_KEY_POINT_EXERCISE:
                case Constants.TYPE_DIFFICULT_POINT_EXERCISE:
                case Constants.TYPE_EASY_WRONG_EXERCISE:
                case Constants.TYPE_SPECIAL_TOPIC_EXERCISE:
                    Session.getSession().put("rewardToyBean",rewardToyBean);

                    Intent specialIntent = new Intent(this,SpecialTopicExerciseActivity.class);
                    specialIntent.putExtra("awardType",3);
                    startActivityAllow(specialIntent);
                    break;
            }
        }
    }

    private void startSmartExam(RewardToyBean rewardToyBean) {
        if(rewardToyBean == null){
            showToast("智能练习玩具奖励信息为空");
            return;
        }

        if(!rewardToyBean.znlx){
            showToast("智能练习暂无题目");
            return;
        }

        onBackAction();

        Session.getSession().put("rewardToyBean",rewardToyBean);

        Intent intent = new Intent(this,ExamActivity.class);
        intent.putExtra("awardType",2);
        startActivityAllow(intent);
    }
}
